import QtQuick 2.7
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.2
import "."

import "./"
import ConvertData 1.0

Item {
    id:root

    //signal mapConfigBtnClicked();
    signal backBtnClicked();


    //property int psaspCaseListViewCurrentIndex:0;

    //    Platform.onDatabaseChanged:{
    //        psaspCaseTableModel.initPsaspCaseData();
    //    }

    Rectangle{
        id:title
        color:View.mainColor
        anchors{
            left:parent.left
            top:parent.top
            right:parent.right

        }
        height:parent.height/14

        Text{
            anchors.fill:parent
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            text:"QTQUICKDEMO"
            font.pointSize: 12
            font.family: View.mainFontFamily
            font.bold: true
            color:"white"
        }


        Rectangle{
            id:closeBtn
            color: View.mainColor
            anchors{
                top:parent.top
                right:parent.right
                bottom:parent.bottom
                topMargin: 5
                bottomMargin: 5

            }

            width:parent.width/21

            Text{
                anchors.fill: parent
                text:"X"
                font.family: "黑体"
                font.pointSize: 14
                font.bold: true
                color:"white"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }

            MouseArea{
                anchors.fill: parent
                onClicked: {
                    Qt.quit();
                }
            }

        }

        Rectangle{
            id:backBtn
            color: View.mainColor
            anchors{
                top:parent.top
                left:parent.left
                bottom:parent.bottom
                topMargin: 5
                bottomMargin: 5
                leftMargin: 5

            }

            width:parent.width/21

            Text{
                anchors.fill: parent
                text:"->"
                font.family: "黑体"
                font.pointSize: 14
                font.bold: true
                color:"white"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }

            MouseArea{
                anchors.fill: parent
                onClicked: {
                    backBtnClicked();
                }
            }

        }

    }

    ColumnLayout{
        opacity: 0
        NumberAnimation on opacity { to: 1; duration: 600 }
        anchors{
            top:title.bottom
            left:parent.left
            right:parent.right
            bottom:parent.bottom

            bottomMargin: 30
            topMargin: 10
        }

        Item{
            id:switchSkinItem
            width:parent.width
            height:parent.height/7+25
            Text{
                id:switchSkinText
                anchors{
                    fill: parent
                    leftMargin: 35
                    rightMargin: 35
                    bottomMargin: parent.height/2

                }
                text:"切换皮肤："
                font.family: View.mainFontFamily
                font.pointSize: View.mainFontSize
                horizontalAlignment: Text.AlignLeft
                verticalAlignment: Text.AlignVCenter
                color:View.mainWordColor//qsFilePathText.enabled?View.mainWordColor:View.enableColor
            }

            RowLayout{
                anchors{
                    fill:parent
                    leftMargin: 35
                    rightMargin: 35
                    topMargin: parent.height/2
                }

                spacing: 5

                Repeater {
                    model: ["#a8df65", "#f5a31a", "#efb960","#ee91bc","#f5a7a7","#f9d89c","#82c4c3","#bc658d"]

                    Rectangle{
                        width:50
                        height:50
                        radius: 25
                        color:modelData

                        MouseArea{
                            anchors.fill: parent
                            onClicked: {
                                View.mainColor=modelData;
                            }
                        }
                    }


                }

            }
        }


        Item{
            id:tableView1Item
            width:parent.width
            height:parent.height/7*2
            Text{
                id:tableView1Text
                anchors{
                    fill: parent
                    leftMargin: 35
                    rightMargin: 35
                    bottomMargin: parent.height/5*4

                }
                text:"表格1："
                font.family: View.mainFontFamily
                font.pointSize: View.mainFontSize
                horizontalAlignment: Text.AlignLeft
                verticalAlignment: Text.AlignVCenter
                color:View.mainWordColor//psaspCaseText.enabled?View.mainWordColor:View.enableColor
            }

            Item{
                anchors{
                    fill:parent
                    leftMargin: 35
                    rightMargin: 35
                    topMargin: parent.height/5
                }

                TableView{
                    id:tableView1
                    anchors.fill: parent

                    horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
                    verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
                    currentRow:0
                    headerDelegate: Rectangle{
                        id:head
                        width:parent.width
                        height:25
                        clip:true
                        color:View.mainColor//psaspCaseTable.enabled?View.mainColor:View.enableColor

                        Rectangle{
                            anchors{
                                left:parent.left
                                right:parent.right
                                bottom:parent.bottom
                            }
                            height:1
                            color:"white"//View.mainColor
                        }

                        Rectangle{
                            anchors{
                                top:parent.top
                                right:parent.right
                                left:parent.left
                            }
                            height:1
                            color:"white"//View.mainColor
                        }

                        Rectangle{
                            anchors{
                                top:parent.top
                                bottom: parent.bottom
                                right:parent.right
                            }
                            width: 1
                            color:"white"//View.mainColor
                        }

                        Text{
                            id:headText
                            anchors.fill: parent
                            text: styleData.value
                            color:"white"//View.mainWordColor
                            font.pixelSize: 13
                            font.family: View.mainFontFamily
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter

                        }
                    }

                    rowDelegate:   Rectangle{
                        height:22
                        color:"transparent"
                    }

                    style: Component{
                        TableViewStyle{
                            frame:Rectangle{
                                color:View.mainColor//psaspCaseTable.enabled?View.mainColor:View.enableColor
                            }
                        }
                    }
//                    model:ConvertTableModel{
//                        id:tableView1Model
//                        tableType:ConvertTableModel.Table_PsaspCase
//                    }

//                    Component.onCompleted: {
//                        var roleList = psaspCaseTableModel.columnRole();
//                        var titleList = psaspCaseTableModel.columnTitle();
//                        var widthList = psaspCaseTableModel.columnWidth();

//                        for(var i=0;i<roleList.length;++i)
//                        {
//                            var role = roleList[i];
//                            var title = titleList[i];
//                            var width = psaspCaseTable.width/3//widthList[i];

//                            var columnObject = columnComponent.createObject(
//                                        psaspCaseTable,{"role":role,"title":title,"width":width})
//                            psaspCaseTable.addColumn(columnObject)
//                        }
//                    }

                    Component{
                        id:columnComponent
                        TableViewColumn{

                            delegate: Rectangle{

                                color:styleData.row==tableView1.currentRow?(tableView1.enabled?View.mainColor:View.enableColor):"transparent";
                                Text{
                                    anchors.fill: parent
                                    text:styleData.value
                                    horizontalAlignment: Text.AlignHCenter
                                    verticalAlignment: Text.AlignVCenter
                                    font.family: View.mainFontFamily
                                    font.pointSize: 10
                                    MouseArea{
                                        anchors.fill: parent
                                        onClicked: {
                                            tableView1.currentRow=styleData.row
                                        }
                                    }
                                }


                                Rectangle{
                                    //visible: styleData.column
                                    anchors{
                                        right:parent.right
                                        top:parent.top
                                        bottom:parent.bottom

                                    }
                                    width:1
                                    color:View.mainColor
                                }
                                Rectangle{
                                    anchors{
                                        right:parent.right
                                        left:parent.left
                                        bottom:parent.bottom

                                    }
                                    height:1
                                    color:View.mainColor
                                }

                            }
                        }


                    }

                    onCurrentRowChanged: {
//                        if(tableView1.currentRow>=0<psaspCaseTableModel.rowCount())
//                        {
//                            var caseNo =psaspCaseTableModel.getCaseNoByRowId(psaspCaseTable.currentRow);
//                            Platform.psaspCaseNo=caseNo;
//                        }


                    }
                }
            }

        }


        Item{
            id:path1
            width:parent.width
            height:parent.height/7
            Text{
                id:path1Text
                anchors{
                    fill: parent
                    leftMargin: 35
                    rightMargin: 35
                    bottomMargin: parent.height/2

                }
                text:"选择文件路径一："
                font.family: View.mainFontFamily
                font.pointSize: View.mainFontSize
                horizontalAlignment: Text.AlignLeft
                verticalAlignment: Text.AlignVCenter
                color:enabled?View.mainWordColor:View.enableColor
                enabled: Platform.isChooseFirstPath?true:false
            }

            RowLayout{
                anchors{
                    fill:parent

                    leftMargin: 35
                    rightMargin: 35
                    topMargin: parent.height/2

                }

                InputPath{
                    id:input1
                    width:550
                    height:30
                    //inputContent:""
                    enabled: Platform.isChooseFirstPath?true:false
                }
                ConvertButton{
                    id:input1Btn
                    width:100
                    height:30
                    text:"选择"
                    enabled: Platform.isChooseFirstPath?true:false

                    onClicked: {
                        path1Dialog.open();
                    }

                }

                FileDialog {
                    id: path1Dialog
                    title: "选择文件"
                    //nameFilters: [ "Text files (*.txt)"]
                    onAccepted: {
                        input1.inputContent=path1Dialog.fileUrl;

                        path1Dialog.close();
                    }
                    onRejected: {
                        path1Dialog.close();
                    }
                }
            }

        }

        Item{
            id:path2
            width:parent.width
            height:parent.height/7
            Text{
                id:path2Text
                anchors{
                    fill: parent
                    leftMargin: 35
                    rightMargin: 35
                    bottomMargin: parent.height/2

                }
                text:"选择文件路径二："
                font.family: View.mainFontFamily
                font.pointSize: View.mainFontSize
                horizontalAlignment: Text.AlignLeft
                verticalAlignment: Text.AlignVCenter
                color:enabled?View.mainWordColor:View.enableColor
                enabled: Platform.isChooseFirstPath?false:true
            }

            RowLayout{
                anchors{
                    fill:parent

                    leftMargin: 35
                    rightMargin: 35
                    topMargin: parent.height/2

                }

                InputPath{
                    id:input2
                    width:550
                    height:30
                    //inputContent:""
                    enabled: Platform.isChooseFirstPath?false:true
                }
                ConvertButton{
                    id:input2Btn
                    width:100
                    height:30
                    text:"选择"
                    enabled: Platform.isChooseFirstPath?false:true

                    onClicked: {
                        path2Dialog.open();
                    }

                }

                FileDialog {
                    id: path2Dialog
                    title: "选择文件"
                    //nameFilters: [ "Text files (*.txt)"]
                    onAccepted: {
                        input2.inputContent=path2Dialog.fileUrl;

                        path2Dialog.close();
                    }
                    onRejected: {
                        path2Dialog.close();
                    }
                }
            }

        }


        Item{
            id:isChooseTheFirstPath
            width:parent.width
            height:parent.height/7-30

            RowLayout{
                anchors{
                    fill: parent
                    leftMargin: 32
                    rightMargin: 35
                    bottomMargin: parent.height/2

                }

                CheckBox {
                    id: control
                    text: qsTr("是否选择文件路径一")
                    checked: true//Platform.isChooseFirstPath
                    font.family: View.mainFontFamily
                    font.pointSize: View.mainFontSize
                    indicator: Rectangle {
                        implicitWidth: 16
                        implicitHeight: 16
                        x: control.leftPadding
                        y: parent.height / 2 - height / 2
                        radius: 3
                        border.color: control.down ? View.mainColor : View.mainColor

                        Rectangle {
                            width: 10
                            height: 10
                            x: 3
                            y: 3
                            radius: 2
                            color: control.down ? View.mainColor : View.mainColor
                            visible: control.checked
                        }
                    }

                    contentItem: Text {
                        text: control.text
                        font: control.font

                        opacity: enabled ? 1.0 : 0.3
                        color: control.down ? View.mainColor : View.mainWordColor
                        verticalAlignment: Text.AlignVCenter
                        leftPadding: control.indicator.width + control.spacing


                    }

                    onCheckedChanged: {
                        Platform.isChooseFirstPath = checked;
                        checkStatusChanged(checked);
                    }
                }
            }
        }

        Item{
            id:nextPageBtn
            width:parent.width
            height:parent.height/7

            ConvertButton{
                anchors.centerIn: parent
                width:120
                height:30
                text:"下一页"

                onClicked: {


                    if(input1.inputContent==""
                            &&Platform.isChooseFirstPath)
                    {
                        Platform.showDialog("警 告","请选择文件路径一！");
                    }
                    else if(input2.inputContent==""
                            &&!Platform.isChooseFirstPath)
                    {
                        Platform.showDialog("警 告","请选择文件路径二！");
                    }
                }

            }
        }

    }


    function checkStatusChanged(isChecked)
    {
        if(isChecked)
        {
            path1Text.enabled=true;
            input1.enabled=true;
            input1Btn.enabled=true;
            path2Text.enabled=false;
            input2.enabled=false;
            input2Btn.enabled=false;

        }
        else
        {
            path2Text.enabled=true;
            input2.enabled=true;
            input2Btn.enabled=true;
            path1Text.enabled=false;
            input1.enabled=false;
            input1Btn.enabled=false;
        }
    }
}
